package ru.evga.inse.server.gwt.common.client;

import ru.evga.gwt.lib.common.client.exception.ExceptionHandler;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.RootLayoutPanel;


public abstract class AbstractApp
{
    private final IAppFactory factory;

    public AbstractApp(IAppFactory factory)
    {
        this.factory = factory;
    }

    public void run()
    {
        GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler()
        {
            public void onUncaughtException(Throwable e)
            {
                ExceptionHandler.handle(e);
            }
        });
        init();
        /* Hide the loading message */
        Element loading = Document.get().getElementById("loading");
        loading.getParentElement().removeChild(loading);
        /* And show the user the shell */
        RootLayoutPanel.get().add(factory.getShellWidget());
    }

    abstract protected void init();
}
